//获取用户列表options hooks
import { useEffect, useState } from "react";
import { userList } from "@/services/project";

export const useUser = () => {
  const [userOptions, setUserOptions] = useState<
    Array<{ label: string; value: number }>
  >([]);

  const fetchUserList = async () => {
    try {
      const { data } = await userList();
      setUserOptions(
        data.map((item: { id: number; showText: string }) => ({
          label: item.showText,
          value: item.id,
        }))
      );
    } catch (error) {
      console.error("Failed to fetch user list:", error);
    }
  };

  useEffect(() => {
    fetchUserList();
  }, []);
  //reflash
  const refreshUserList = () => {
    fetchUserList();
  };

  return { userOptions, refreshUserList };
};
